const Controller=qguan("Controller")
import http  from "http";
/**
 * web端依赖
 */
@Controller("/api")
export default  class ApiCtrl{
    constructor(){

    }
    //用户登录
    @Controller("/")
    find(req,res,url){

        let _this=this;
        let path= url.pathname.replace(new RegExp("^/api"),"" );



        try{
            let opt = {
                host:'127.0.0.1',
                port:'8080',
                 method:req.method,//这里是发送的方法
                path:path,   //这里是访问的路径
                headers:req.headers
            }
            //以下是接受数据的代码
            let body = '';
            let req11 = http.request(opt, function(res2) {
                console.log("Got response: " + res2.statusCode);
                res2.
                on('data',function(d)
                {
                    body += d;
                })
                    .on('end', function()
                    {
                    console.log(res2.headers)
                    console.log(body)
                    res.write(body)
                    res.end();
                });

            }).on('error', function(e) {
                console.log("Got error: " + e.message);
            })
            req11.write(JSON.stringify(req.body));
            req11.end();

        }catch (e) {
            res.write(JSON.stringify({
                message: '异常'
            }))
            res.end();
            return;
        }

    }


}



